package cn.lotusnut.rabbitmqboot.kill;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @Author JiangMing Zhou
 * @Date 2022/12/1 16:20
 * @Version 1.8
 */
@Slf4j
@Component
public class KillDeadConsumer {

    /**
     * 消费消息
     */
    @RabbitListener(queues = "kill_dead_queue")
    public void consumer(Channel channel, Message message) throws IOException {
        String user = new String(message.getBody(), StandardCharsets.UTF_8);
        log.debug(user + "秒杀失败");
        //向前端返回消息

        //确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
